﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Win.BLL;

namespace ShiYan3
{
    public partial class DishForm : Form
    {
        private DishBLL dishBLL = new DishBLL();
        public DishForm()
        {
            InitializeComponent();
        }

        private void DishForm_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = dishBLL.GetDishInfos();
            comboBox1.SelectedIndex = comboBox1.Items.IndexOf("全部");
            comboBox2.SelectedIndex = 0;
            dataGridView1.Columns[0].HeaderText = "编号";
            dataGridView1.Columns[1].HeaderText = "菜名";
            dataGridView1.Columns[2].HeaderText = "价格";
            dataGridView1.Columns[3].HeaderText = "种类";
            dataGridView1.Columns[4].Visible = false;
            dataGridView1.Columns[5].Visible = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String dish_name = textBox1.Text.Trim();
            String dish_type = comboBox1.SelectedItem.ToString().Trim();
            dataGridView1.DataSource = dishBLL.GetDishesByNT(dish_name, dish_type);
            dataGridView1.Columns[0].HeaderText = "编号";
            dataGridView1.Columns[1].HeaderText = "菜名";
            dataGridView1.Columns[2].HeaderText = "价格";
            dataGridView1.Columns[3].HeaderText = "种类";
            dataGridView1.Columns[4].Visible = false;
            dataGridView1.Columns[5].Visible = false;
        }

        private void button_add_Click(object sender, EventArgs e)
        {
            string name = textBox_dish.Text.Trim();
            string type = comboBox2.SelectedItem.ToString().Trim();
            decimal price = decimal.Parse(textBox_price.Text);
            dishBLL.AddDish(name, type, price);
            dataGridView1.DataSource = dishBLL.GetDishInfos();
            dataGridView1.Columns[0].HeaderText = "编号";
            dataGridView1.Columns[1].HeaderText = "菜名";
            dataGridView1.Columns[2].HeaderText = "价格";
            dataGridView1.Columns[3].HeaderText = "种类";
            dataGridView1.Columns[4].Visible = false;
            dataGridView1.Columns[5].Visible = false;
            textBox_dish.Text = "";
            textBox_price.Text = "";
        }

        private void button_cencel_Click(object sender, EventArgs e)
        {
            textBox_dish.Text = "";
            textBox_price.Text = "";
        }

        private void button_del_Click(object sender, EventArgs e)
        {
            int i = dataGridView1.CurrentRow.Index;
            int id = int.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString());
            dishBLL.DeleteDishById(id);
            dataGridView1.DataSource = dishBLL.GetDishInfos();
            dataGridView1.Columns[0].HeaderText = "编号";
            dataGridView1.Columns[1].HeaderText = "菜名";
            dataGridView1.Columns[2].HeaderText = "价格";
            dataGridView1.Columns[3].HeaderText = "种类";
            dataGridView1.Columns[4].Visible = false;
            dataGridView1.Columns[5].Visible = false;
        }
    }
}
